#!/bin/bash
# scripts/health-check.sh

echo "检查服务健康状态..."

# 检查私有仓库
echo "检查私有仓库..."
if curl -s http://localhost:5000/v2/_catalog > /dev/null 2>&1; then
    echo "✓ 私有仓库: 正常"
else
    echo "✗ 私有仓库: 异常"
fi

# 检查 MySQL
echo "检查 MySQL..."
if docker-compose exec mysql mysqladmin ping -h localhost -u gd_user -pgd_password > /dev/null 2>&1; then
    echo "✓ MySQL: 正常"
else
    echo "✗ MySQL: 异常"
fi

# 检查 ClickHouse
echo "检查 ClickHouse..."
if curl -s http://localhost:8123/ping > /dev/null 2>&1; then
    echo "✓ ClickHouse: 正常"
else
    echo "✗ ClickHouse: 异常"
fi

# 检查 Redis
echo "检查 Redis..."
if docker-compose exec redis redis-cli ping > /dev/null 2>&1; then
    echo "✓ Redis: 正常"
else
    echo "✗ Redis: 异常"
fi

# 检查 Kafka
echo "检查 Kafka..."
if docker-compose exec kafka kafka-topics --bootstrap-server localhost:9092 --list > /dev/null 2>&1; then
    echo "✓ Kafka: 正常"
else
    echo "✗ Kafka: 异常"
fi

# 检查 Flink
echo "检查 Flink..."
if curl -s http://localhost:8081/overview > /dev/null 2>&1; then
    echo "✓ Flink: 正常"
else
    echo "✗ Flink: 异常"
fi

# 检查 SpringBoot 应用
echo "检查 SpringBoot 应用..."
if curl -s http://localhost:8080/api/actuator/health > /dev/null 2>&1; then
    echo "✓ SpringBoot 应用: 正常"
else
    echo "✗ SpringBoot 应用: 异常"
fi

echo "健康检查完成"
